<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no" />
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <style>
        html, body {
            background-color: #f8f8f8;
        }
        .main ul li .li_box {
            height: 50px;
            line-height: 50px;
            display: -webkit-box;
            display: -webkit-flex;
            align-items: center;
            background-color: #fff;
            border-bottom: 1px solid #e8e8e8;
            padding: 0 15px;
        }
        .main ul li:last-child .li_box {
            border-bottom: none;
        }
        .main ul li .li_box .li_boxl {
            font-size: 15px;
            color: #333;
        }
        .main ul li .li_box .li_boxr {
            color: #999;
            font-size: 12px;
            padding-left: 10px;
            flex: 1;
            -webkit-flex: 1;
            box-flex: 1;
            -webkit-box-flex: 1;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            text-align: right;
        }
        .main ul li .li_box .li_boxr .rm_span {
        	color: #e62442;
        	font-size: 12px;
        	display: block;
        }
        .main ul li .li_box .li_boxr .num_span {
        	color: #333;
        	font-size: 12px;
        }
    </style>
</head>
<body>
    <div class="main">
    	<ul>
            <li>
                <div class="li_box">
                    <div class="li_boxl">优惠券金额</div>
                    <div class="li_boxr"><span class="rm_span">RM <span class="price"></span></span></div>
                </div>
            </li>
            <li>
                <div class="li_box">
                    <div class="li_boxl">开始时间</div>
                    <div class="li_boxr begin_time"></div>
                </div>
            </li>
            <li>
                <div class="li_box">
                    <div class="li_boxl">结束时间</div>
                    <div class="li_boxr end_time"></div>
                </div>
            </li>
            <li>
                <div class="li_box">
                    <div class="li_boxl">发送数量</div>
                    <div class="li_boxr"><span class="
                    total_num"></span> <span class="num_span">张</span></div>
                </div>
            </li>
    	</ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
    apiready = function(){
        id = api.pageParam.id;
        shop = $api.getStorage('shop_data');
        fnGetTicketDetail();

        api.addEventListener({
            name: 'deleteTicketEvent'
        }, function(ret, err) {
            if (ret) {
                api.ajax({
                    url: rootPath+'/api/seller/delete_ticket',
                    method: 'post',
                    data: {
                        values: { 
                            shop_id: shop.id,
                            token: shop.token,
                            id : id
                        },
                    }
                }, function(ret, err) {
                    if (ret) {
                        if(ret.status == 200) {
                            api.sendEvent({
                                name: 'ticketChangeEvent',
                                extra: {
                                }
                            });
                            api.toast({
                                msg: '删除成功',
                                location: 'middle'
                            });
                            setTimeout(function(){
                                api.closeWin();
                            },1000)
                        }
                    } else {
                        alert(JSON.stringify(err.msg));
                    }
                });
            }
        });
    };

    function fnGetTicketDetail() {
        api.ajax({
            url: rootPath+'/api/seller/ticket_detail',
            method: 'post',
            data: {
                values: { 
                    shop_id: shop.id,
                    token: shop.token,
                    id : id,
                },
            }
        }, function(ret, err) {
            if (ret) {
                $('.price').text(ret.data.price);
                $('.begin_time').text(ret.data.begin_time);
                $('.end_time').text(ret.data.end_time);
                if(ret.data.total_num == 0) {
                    $('.total_num').text('无限');
                }else {
                    $('.total_num').text(ret.data.total_num);
                }
            } else {

            }
        });
    }

</script>
</html>